/**
 * @Description:定位
 */
export function getLocation() {
  return new Promise((resolve, reject) => {
    uni.getFuzzyLocation({
      success: ({ longitude, latitude }) => {
        resolve({ longitude, latitude });
      },
      fail: (err) => {
        console.log(err);
        reject();
      },
    });
  });
}

/**
 * @Description: 判断用户是否授权
 * @param {string} auth
 */
export function getSetting(auth = "scope.userLocation") {
  return new Promise((resolve, reject) => {
    uni.getSetting({
      success: (res) => {
        if (auth in res.authSetting) {
          if (res.authSetting[auth]) {
            resolve();
          } else {
            reject();
          }
        } else {
          reject();
        }
      },
      fail: (err) => {
        reject();
      },
    });
  });
}

/**
 * @Description:调用客户端小程序设置界面
 * @param {string} auth 校验的权限的值
 */
export function openSetting(auth = "scope.userLocation") {
  return new Promise((resolve, reject) => {
    uni.openSetting({
      success: (res) => {
        if (res.authSetting[auth]) {
          resolve();
        } else {
          reject();
        }
      },
    });
  });
}
